import poplib
import email
from email.parser import Parser

# 邮箱配置
POP3_SERVER = "pop.163.com"
POP3_PORT = 995
EMAIL = "justforted@163.com"
AUTH_CODE = "HLykuQC6dsZVb7js"

# 连接到POP3服务器
pop_conn = poplib.POP3_SSL(POP3_SERVER, POP3_PORT)
pop_conn.user(EMAIL)
pop_conn.pass_(AUTH_CODE)

# 获取邮件数量和大小
message_count, mailbox_size = pop_conn.stat()
print(f"邮件数量: {message_count}, 邮箱大小: {mailbox_size} bytes")

# 获取所有邮件
for i in range(1, message_count + 1):
    response, lines, octets = pop_conn.retr(i)
    message_content = b"\r\n".join(lines).decode("utf-8")
    message = Parser().parsestr(message_content)

    # 处理邮件...

pop_conn.quit()
